//
//  UIBarButtonItem+Item.m
//  BuDeJie
//
//  Created by haoran on 16/4/1.
//  Copyright © 2016年 xuhaoran. All rights reserved.
//

#import "UIBarButtonItem+Item.h"

@implementation UIBarButtonItem (Item)

/**** 设置导航条按钮的图片,高亮图片,和执行的方法 ****/
+(UIBarButtonItem *)buttonItemWithImage:(UIImage *)image andWithHighlightImage:(UIImage *)highImage addTarget: (id)target andAction:(SEL) action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highImage forState:UIControlStateHighlighted];
    //自适应大小
    [btn sizeToFit];
    //监听按钮点击
    [btn addTarget:target action: action forControlEvents:UIControlEventTouchUpInside];
    
    //包装成UIView,这样按钮点击范围能控制成自身大小
    UIView * view = [[UIView alloc]initWithFrame:btn.frame];
//    view.backgroundColor = [UIColor yellowColor];
    [view addSubview:btn];
    return [[UIBarButtonItem alloc]initWithCustomView:view];
}

/****设置导航条按钮的图片,选中图片,和执行的方法 ****/
+(UIBarButtonItem *)buttonItemWithImage:(UIImage *)image andWithSelectedImage:(UIImage *)highImage addTarget: (id)target andAction:(SEL) action{

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highImage forState:UIControlStateSelected];
    //自适应大小
    [btn sizeToFit];
    //监听按钮点击
    [btn addTarget:target action: action forControlEvents:UIControlEventTouchUpInside];
    
    //包装成UIView,这样按钮点击范围能控制成自身大小
    UIView * view = [[UIView alloc]initWithFrame:btn.frame];
//    view.backgroundColor = [UIColor yellowColor];
    [view addSubview:btn];
    return [[UIBarButtonItem alloc]initWithCustomView:view];
}


@end
